import qs from 'qs'
import request from '../utils/request'

// 流程预览查询
export const queryModelJson = (modelId, versionId) => {
  let url
  if (versionId) {
    url = `modeler-app/rest/models/${modelId}/history/${versionId}/model-json`
  } else {
    url = `modeler-app/rest/models/${modelId}/model-json`
  }
  return request({
    method: 'GET',
    url,
    params: {
      nocaching: Date.now()
    }
  })
}

// 流程编辑查询
export const queryEditorJson = (modelId) => {
  return request({
    method: 'GET',
    url: `modeler-app/rest/models/${modelId}/editor/json`,
    params: {
      version: Date.now()
    }
  })
}
// 流程编辑保存
export const saveEditorJson = (modelId, data) => {
  return request({
    method: 'POST',
    url: `modeler-app/rest/models/${modelId}/editor/json`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  })
}

// 验证流程图数据
export const validateData = (data) => {
  return request({
    method: 'POST',
    url: `modeler-app/rest/model/validate`,
    data
  })
}

// 查询流程编辑器设置
export const queryEditorStencil = () => {
  return request({
    method: 'GET',
    url: 'modeler-app/rest/stencil-sets/editor',
    params: {
      version: Date.now()
    }
  })
}
// 查询oryxplugins
export const queryOryxPlugins = () => {
  return request({
    method: 'GET',
    url: 'modeler/editor-app/plugins.xml'
  })
}

// 查询oryxplugins
export const loadLang = () => {
  return request({
    method: 'GET',
    url: 'modeler/i18n/zh-CN.json'
  })
}